﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Bricks.BaseFramework.Utility
{
    /*********************************************************
    * 1.版权：积木工场 Bricks Factory
    * 2.作用：加密算法
    * 3.创建人：罗泽新
    * 4.创建日期：2012-04-22
    * 5.最后修改人：罗泽新
    * 6.最后修改日期：2012-04-27
    * 7.修改项目：
    * *******************************************************/
    /// <summary>
    /// 加密
    /// </summary>
    public class Encryption
    {
        /// <summary>
        /// MD5加密算法
        /// </summary>
        /// <param name="textToEncrypt"></param>
        /// <returns></returns>
        public static string EncryptByMD5(string textToEncrypt)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] inBytes = Encoding.Default.GetBytes(textToEncrypt);
            int dd = md5.GetHashCode();
            byte[] outBytes = md5.ComputeHash(inBytes);
            StringBuilder encryptedText = new StringBuilder();
            for (int i = 0; i < outBytes.Length; i++)
                encryptedText.Append(outBytes[i].ToString("X2"));
            return encryptedText.ToString();
        }
    }
}
